<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div style="margin-top: 20px;">
</div>
<form class="layui-form" id="admin">
  
  <div class="layui-form-item">
    <label class="layui-form-label">成员姓名</label>
    <div class="layui-input-inline">
      <input name="mname" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$member.mname"}value="{$member.mname}"{/notempty}>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">成员性别</label>
    <div class="layui-input-inline">
      <input type="radio" name="msex" value="1" class="layui-input" {notempty name="$member"}{eq name="$member.msex" value="1"}checked{/eq}{/notempty}>男
      <input type="radio" name="msex" value="0" class="layui-input" {notempty name="$member"}{eq name="$member.msex" value="0"}checked{/eq}{/notempty}>女
    </div>
  </div>

  <div class="layui-upload" id="upload-thumb">
    <label class="layui-form-label">头像</label>
    <button type="button" class="layui-btn" id="thumb">上传头像</button>
    <div class="layui-upload-list">
      <label class="layui-form-label"></label>
      <img class="layui-upload-img" id="demo1" width="150" height="150" {notempty name="$member.image"}src="{$member.image|geturl}"{/notempty}>
      <p id="demoText"></p>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">手机</label>
    <div class="layui-input-block" style="max-width:500px;">
      <input type="text" placeholder="请输入内容" class="layui-input" name="phone" {notempty name="$member.phone"}value="{$member.phone}"{/notempty}>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">城乡</label>
    <div class="layui-input-block" style="max-width:500px;">
      <input type="text" placeholder="请输入内容" class="layui-input" name="address" {notempty name="$member.address"}value="{$member.address}"{/notempty}>
    </div>
  </div>

  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block" style="max-width:1000px;">
      <textarea placeholder="请输入内容" class="layui-textarea" name="content" id="container" style="border:0;padding:0">{notempty name="$member.content"}{$member.content}{/notempty}</textarea>
    </div>
  </div>

  {notempty name="$member"}
  <input type="hidden" name="mid" value="{$member.mid}">
  {/notempty}
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
  
</form>


<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>

<script>
  layui.use('upload', function(){
    var upload = layui.upload;
    //执行实例
    var uploadInst = upload.render({
      elem: '#thumb' //绑定元素
      ,url: "{:url('common/upload')}" //上传接口
      ,done: function(res){
        //上传完毕回调
        if(res.code == 2) {
          $('#demo1').attr('src',res.src);
          $('#upload-thumb').append('<input type="hidden" name="image" value="'+ res.id +'">');
        } else {
          layer.msg(res.msg);
        }
      }
      ,error: function(){
        //请求异常回调
        //演示失败状态，并实现重传
        var demoText = $('#demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
    });
  });
</script>
<script>
  layui.use(['layer', 'form'], function() {
      var layer = layui.layer,
          $ = layui.jquery,
          form = layui.form;
      $(window).on('load', function() {
          form.on('submit(admin)', function(data) {
              $.ajax({
                  url:"{:url('admin/member/publish')}",
                  data:$('#admin').serialize(),
                  type:'post',
                  async: false,
                  success:function(res) {
                      layer.msg(res.msg);
                      if(res.code == 1) {
                          setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                          },1500) 
                      }
                  }
              })
              return false;
          });
      });
  });
</script>

<!-- 加载编辑器的容器 -->
<script id="container" name="content" type="text/plain">
    这里写你的初始化内容
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
  var ue = UE.getEditor('container');
</script>

</body>
</html>